package onjava;

import java.util.function.Supplier;

public class BasicSupplier<T> implements Supplier<T> {
	private Class<T> type;

	public BasicSupplier(Class<T> type) {
		this.type = type;
	}

	@Override
	public T get() {
		try {
			return type.newInstance();
		} catch (InstantiationException | IllegalAccessException e) {
			throw new RuntimeException(e);
		}
	}

	public static <T> Supplier<T> create(Class<T> type) {
		return new BasicSupplier<>(type);
	}
}
